#!/usr/bin/env python
# encoding=utf-8
import re
import sys

import utils

reload(sys)
sys.setdefaultencoding("utf-8")


def run():
    url = 'https://zeustracker.abuse.ch/blocklist.php?download=ipblocklist'
    content = utils.get_url_content(url)

    ips = []
    for index, ip in enumerate(re.findall(ur'\d+\.\d+\.\d+\.\d+', content)):
        ips.append({
            '_id': ip,
            "sourceUrl": "https://zeustracker.abuse.ch/blocklist.php?download=ipblocklist",
            "sourceName": "ZeusBotnetPublic",
            "detail": "",
            "cause": ""
        })
    utils.save2db(ips)


if __name__ == '__main__':
    run()
